package com.fuluwa.domain.file.model;

import java.io.File;

import javax.persistence.MappedSuperclass;

import com.fuluwa.domain.shared.AbstractIdMantainceDomainObject;
import com.fuluwa.infra.exception.PersistenceException;
import com.fuluwa.infra.lucene.TikaManager;
/**
Solr Config:
<pre>

<field name="file_name" type="text" indexed="true" stored="true"/>
	 <field name="file_catagory" type="text" indexed="true" stored="true"  multiValued="true"/>
   <field name="file_content" type="text" indexed="true" stored="true"/>
   
    <copyField source="file_name" dest="text"/>
   <copyField source="file_catagory" dest="text"/>
	 <copyField source="file_content" dest="text"/>
	 
	 <fieldType name="text" class="solr.TextField"> 
     <analyzer> 
       <tokenizer class="org.wltea.analyzer.solr.IKTokenizerFactory"/>
       <!-- isMaxWordLength="true" --> 
     </analyzer> 
   </fieldType> 
</pre>
* @author yongxia
*
*/
@MappedSuperclass
public abstract class AbstractFileInfo extends AbstractIdMantainceDomainObject {
//	public static enum FileType {
//		FILE, PICTURE
//	}

	private String name;
	private String phiscalPath;

	private boolean indexed = false;
public AbstractFileInfo() {
}
  
	public AbstractFileInfo(Long id) {
		super(id);
	}

	public AbstractFileInfo(String name, String phiscalPath) {
		this.name = name;
		this.phiscalPath = phiscalPath;
	}
	
	public String getName() {
		return name;
	}

	public String getPhiscalPath() {
		return phiscalPath;
	}
	public File getPhiscalPathFile() {
		return new File(phiscalPath);
	}

//	public abstract FileType getType();

	public void updatePhiscalPath(String phiscalPath) throws PersistenceException {
		this.phiscalPath = phiscalPath;
		update();
	}

	public void updateIndexed() throws PersistenceException {
		this.indexed = true;
		update();
	}

	public String loadAsString() throws Exception {
		TikaManager tikaManager = new TikaManager(getPhiscalPathFile());
		return tikaManager.getContent();
	}

	public boolean isIndexed() {
		return indexed;
	}
	
}
